use "14_18cfps_0908_corrupt.dta", replace 
log using mylog.log, replace

sort pid time
tsset pid time 





replace webn=0 if webn==.


gen loglgdppc=log(lgdppc)
gen loglpop=log(lpop)

gen loglocal_antic=log(local_antic)

label variable number_1y "Corruption (recent 1 year)" 

label variable number_2y "Corruption (recent 2 year)" 

label variable webn "News Access (Internet)"

label variable tvn "News Access (TV)"

label variable party "CCP member"

label variable age "Age"

label variable maritals "Married"

label variable eduy "Years of Education"

label variable jobsector_n "Public Sector Empoloyee"

label variable urban "Urban"

label variable rincome "Income Level (Subjective)"

label variable rsocial_status "Social Status (Subjective)"

label variable loglgdppc "Lagged GDP per Capita (ln)"

label variable loglpop "Lagged population (ln)"

label variable local_antic "Anti-corruption Efforts"

label variable loglocal_antic "Anti-corruption Efforts (ln)"

/* Key independent variables:
wy_number_1y_contig_s refers to the average number of corruption investigations across neighboring provinces (lagged one year).
wy_number_2y_contig_s refers to the average number of corruption investigations across neighboring provinces (lagged two years).
wy_number_1y_contig_eco_s refers to the average number of corruption investigations across economically similar provinces (lagged one year).
wy_number_2y_contig_eco_s refers to the average number of corruption investigations across economically similar provinces (lagged two years).
*/


est clear

//table 1

xtreg politrust number_1y  webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 

eststo
xtreg politrust number_1y c.wy_number_1y_contig_s  i.time, fe vce(cluster provcd) 

eststo

xtreg politrust number_1y c.wy_number_1y_contig_s webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo
esttab using number_1y_new.csv, star(* 0.05 ** 0.01) r2 b(2) se(2) label replace

//table 2	   

est clear

xtreg politrust number_2y webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 

eststo
xtreg politrust number_2y c.wy_number_2y_contig_s  i.time, fe vce(cluster provcd) 

eststo

xtreg politrust number_2y c.wy_number_2y_contig_s webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo


esttab using number_2y.csv, star(* 0.05 ** 0.01) r2 b(2) se(2) label replace 

//table 3
est clear


xtreg politrust number_1y c.wy_number_1y_contig__eco_s  i.time, fe vce(cluster provcd) 

eststo

xtreg politrust number_1y c.wy_number_1y_contig__eco_s webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo

xtreg politrust number_2y c.wy_number_2y_contig_eco_s  i.time, fe vce(cluster provcd) 

eststo
xtreg politrust number_2y c.wy_number_2y_contig_eco_s webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo
esttab using number_eco.csv, star(* 0.05 ** 0.01) r2 b(2) se(2) label replace


//table 4
est clear
xtreg politrust number_1y c.wy_number_1y_contig_s##c.webn tvn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo

xtreg politrust number_1y c.wy_number_1y_contig_s##c.tvn webn party age maritals eduy jobsector_n urban rincome rsocial_status loglgdppc loglpop loglocal_antic  i.time, fe vce(cluster provcd) 
eststo
esttab using number_1y_inter.csv, star(* 0.05 ** 0.01) r2 b(2) se(2) label 	replace   


// table 5 checking selective bias 
//using data without removing respondents who moved to other provinces across three waves 

//check selective bias

use "cfps_2014_16_18_moversincluded", replace 
//check people who moveed to another provinces during 2014 and 2018. 
duplicates t pid provcd, gen(du1)
tab du1


gen du_all=1 // people who always stay in the same province 
replace du_all=0 if du1==0 | du1==1 // people who moved to another provinces between 2014 and 2018

ttest politrust if time==0, by(du_all) //compare baseline political trust in 2014 between movers and non-movers.




log close
